import urllib.request
import urllib.parse
from http import cookiejar

headers = {
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36",
}

url = "http://www.renren.com/ajaxLogin/login?1=1&uniqueTimestamp=2019631656801"

data = {
    "email":"gaohj5@163.com",
    "icode":"",
    "origURL":"	http://www.renren.com/home",
    "domain":"renren.com",
    "key_id":1,
    "captcha_type":"web_login",
    "password":"7588a7ecaf772a704035a2cbcd08ebc6586cac4e0003d0794947ed28bfab0e7e",
    "rkey":"18e088a7abd9a93c342722b9641f4b3e",
    "f":"",
}

filename = 'renrencookie.txt'
cookies = cookiejar.LWPCookieJar(filename=filename)
cookie_jar = urllib.request.HTTPCookieProcessor(cookies)
opener = urllib.request.build_opener(cookie_jar)
urllib.request.install_opener(opener) #创建全局打开器


#发送请求
data = urllib.parse.urlencode(data).encode()

req = urllib.request.Request(url,data=data,headers=headers)
response = urllib.request.urlopen(req)
print(response.read().decode())
cookies.save()